﻿@{
    ViewBag.Title = "角色管理";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}
<script type="text/javascript">
    function doSearch() {
        $('#dg').datagrid('load', {
            RoleName: $('#RoleName').val()
        });
    }
    function addRoleInfo() {
        $('#dlg').dialog('open').dialog('setTitle', '新增');
        url = '/SystemSet/AddRoleInfo';
    }

    function editRoleInfo() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $('#dlg').dialog('open').dialog('setTitle', '编辑');
            $('#fm').form('load', row);
            url = "/SystemSet/EditRoleInfo";
        }
    }

    function delRoleInfo() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/SystemSet/DelRoleInfo", { RoleId: row.RoleId }, function (json) {
                Helper.Show(json.Msg);
                if (json.Code == 1) {
                    doSearch();
                }
            });
        });
    }
    function saveRole() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                $.messager.show({
                    title: '消息提示',
                    msg: json.Msg
                });
                if (json.Code == 1) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').datagrid('reload');
                }
            }
        });
    }
</script>
<table id="dg" class="easyui-datagrid" style="width:100%; height: 400px;"
       url="/SystemSet/GetRoleInfoList" toolbar="#tb" title="角色列表" rownumbers="true" pagination="true"
       pagelist="[15]" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="RoleName">
                角色名称
            </th>
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <span>角色名称:</span>
    <input id="RoleName" class="easyui-textbox " />
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addRoleInfo()">添加</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editRoleInfo()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delRoleInfo()">删除</a>
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-save'"
     closed="true" style="width: 380px; height: 200px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <form id="fm" method="post" novalidate>
        <input name="RoleId" value="" type="hidden" />
        <div class="fitem">
            <label>
                角色名称:
            </label>
            <input name="RoleName" class="easyui-validatebox textbox" data-options="required:true,validType:'length[1,20]'" style="width: 173px; height: 30px;" autocomplete="off" />
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveRole()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
